// pages/edit2/edit2.js
Page({

  data: {   arr:[],near_id:'',goods_id:'',last:''

  },

  onLoad: function (options) {
    console.log(options);
    
      let arr=[]
      arr.push(options.url1,options.url2)
      this.setData({arr,near_id:options.near_id,goods_id:options.goods_id})
  },
  navcanvas(e){
    wx.uploadFile({
      filePath:e.currentTarget.dataset.url ,
      name: 'file',
      url: 'https://zujieba.com/Api/upload/upload.html',
      success:(res)=>{
        console.log(res);
        let data=JSON.parse(res.data)
        let url="https://zujieba.com/uploads/"+data.name
        wx.navigateTo({
          url: '/pages/cropper/canvas?url='+e.currentTarget.dataset.url+'&index='+e.currentTarget.dataset.index,
        })
      }
    })
    
  },
  navprint(){
    let arr1=[]
    for(var i=0;i<this.data.arr.length;i++){
      wx.uploadFile({
        filePath: this.data.arr[i],
        name: 'file',
        url: 'https://zujieba.com/Api/upload/upload.html',
        success:(res)=>{
          let url=JSON.parse(res.data).name
          arr1.push(url)
          if(arr1.length==this.data.arr.length){
            wx.request({
              url: 'https://zujieba.com/Api/upload/canvas.html',
              //身份证type是1
              data:{pic:arr1[0],img:arr1[1],type:2},
              method:'POST',
              success:(res)=>{
                console.log(res);
                //拼接两张照片的url1
             let url1= "https://zujieba.com/uploads/"+ res.data.data
            this.throttle(()=>{ wx.navigateTo({
              url: '/pages/fileprint/print/print?url='+url1+"&name="+url1+"&near_id="+this.data.near_id+'&goods_id='+this.data.goods_id,
            })},2000)
                
                
              }
            })
          }
          
        }
      })
    }
  
 
   },
    //节流
 throttle:function(func,wait){
  console.log(func,wait);
  
  let last =this.data.last
  console.log(last);
  
  let current_time= +new Date()
  if(current_time-last>wait){
    console.log(1111);
      console.log(current_time,current_time-last);
      
      func()
      last=+new Date()
      this.setData({
        last
      })
  }}
})